package com.panda.admin.interfaces.log.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panda.admin.interfaces.log.service.SystemLogService;
import com.panda.admin.interfaces.log.mapper.SystemLogMapper;
import com.panda.admin.login.dto.LogDto;
import com.panda.admin.login.entity.SystemLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author tucy123
* @description 针对表【system_log(日志表)】的数据库操作Service实现
* @createDate 2023-07-11 10:58:58
*/
@Service
public class SystemLogServiceImpl extends ServiceImpl<SystemLogMapper, SystemLog> implements SystemLogService{

    @Autowired
    SystemLogMapper systemLogMapper;

    /**
     * 条件分页查询
     * @param logDto
     * @return
     */
    @Override
    public Page<SystemLog> pageList(LogDto logDto) {
        Page<SystemLog> page = new Page<>(logDto.getPageNum(),logDto.getPageSize());

        QueryWrapper<SystemLog> wrapper = new QueryWrapper<>();
        wrapper.like(ObjectUtil.isNotEmpty(logDto.getOperator()),"operator",logDto.getOperator()).orderByDesc("create_time");

        return systemLogMapper.selectPage(page,wrapper);
    }

    /**
     * 删除记录
     * @param ids
     * @return
     */
    @Override
    public Boolean deleteLogs(List<Long> ids) {
        int i = systemLogMapper.deleteBatchIds(ids);
        return i != 1;
    }
}




